<?
//Mail 0.0.1
class sym_mail extends symbiont{
    public function __construct(){
        
    }
    public function ___main($design){
        if(!$design) $design="symbionts/mail/main";
        $d=new design($design, 'mail');
    }
    public function ___ajax($design){
        global $kernel;
        if(isset($_POST['name'])&&isset($_POST['phone'])&&isset($_POST['email'])&&isset($_POST['message'])&&isset($_POST['code'])){
            if($_POST['code']!=$_SESSION['code']){
                $l=new label('mail_capcha_error');
                print '{"type":false, "result":"'.$l->get().'"}';
                return;
            }
            $kernel->library_add('mail');
            $msg="Name: ".$_POST['name']."<br/>";
            $msg.="Phone: ".$_POST['phone']."<br/>";
            $msg.="Email: ".$_POST['email']."<br/>";
            $msg.=$_POST['message'];
            $to='info@simonyan.am';
            $mail=new mail($to, $_POST['name'], $_POST['email'], 'From the contact us page', $msg);
            if($mail->send()){
                $l=new label('mail_sended');
                print '{"type":true, "result":"'.$l->get().'"}';
            }
            else{
                $l=new label('mail_sending_error');
                print '{"type":false, "result":"'.$l->get().'"}';
            }
        }
    }
}
?>